package com.wash.shoes.factory;

import com.wash.shoes.handler.DataPermissionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 数据权限处理器工厂
 */
@Component
public class DataPermissionHandlerFactory {
    private final Map<String, DataPermissionHandler> handlerMap = new HashMap<>();

    @Autowired
    public DataPermissionHandlerFactory(List<DataPermissionHandler> handlers) {
        for (DataPermissionHandler handler : handlers) {
            handlerMap.put(handler.getType(), handler);
        }
    }

    /**
     * 获取数据权限处理器
     */
    public DataPermissionHandler getHandler(String type) {
        return handlerMap.get(type);
    }
}